# -*- coding: utf-8 -*-
# @Time : 2021/9/10 10:45
# @Author : 阿怪
# @Email : scg@gmail.com
# @File : CRM-ST-YX-083.py
# @Project : crm自动化测试项目实战
''' 验证邮件模板的添加功能—正确输入所有信息'''

from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from selenium.webdriver.common.alert import Alert  # 把弹窗封装成类Alert

driver = webdriver.Chrome()
cookie = {'name': 'PHPSESSID', 'value': '0onrpth7nsd6mbi1hfgi99o2b1'}  # 获取到cookid
driver.get('http://192.168.1.140/')  # 访问服务器
driver.add_cookie(cookie)
driver.get('http://192.168.1.140/crm3/index.php?m=email&a=index')
#进入邮件模板设置首页

#1.进入邮件模板编辑界面
add_email_locator = (By.ID,'add')   #添加邮件模板定位器
driver.find_element(*add_email_locator).click()   #点击添加邮件模板
sleep(4)

#2.添加内容
tempalte_locator = (By.NAME,'subject')   #模板名称定位器
email_tittle_locator= (By.NAME,'title')   #邮件主题定位器
email_text_locator = (By.ID,'content')  #邮件内容定位器
submit_locator = (By.NAME,'submit')     #保存按钮定位器

driver.find_element(*tempalte_locator).send_keys('生日模板')
driver.find_element(*email_tittle_locator).send_keys('生日主题')
driver.find_element(*email_text_locator).send_keys('生日快乐呀')
driver.find_element(*submit_locator).click()

#3.回到邮件设置首页，获取第一条的模板名称是否为“生日模板”，是则通过
text = driver.find_element(By.CSS_SELECTOR,'#form1 > div:nth-child(2) > table > tbody > tr > td:nth-child(2)').text
print(text)

sleep(2)
driver.quit()
